package com.zhuge_new.Activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.maning.mndialoglibrary.MToast;
import com.zhuge_new.Base.BaseActivity;
import com.zhuge_new.R;
import com.zhuge_new.http.StringDialogCallback;
import com.zhuge_new.share.BaseHttp;
import com.zhuge_new.untils.ActivityStack;
import com.zhuge_new.untils.PreferencesUtils;

import java.sql.BatchUpdateException;

/**
 * Created by lenovo on 2018-09-12.
 */

public class FeedBackActivity extends BaseActivity implements View.OnClickListener {

    private EditText feedback_content;
    private EditText et_contract_info;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);
        init_title();
    }

    @Override
    public void init_title() {
        super.init_title();
        TextView tv_title=findViewById(R.id.tv_nav_title);
        ImageView iv_back=findViewById(R.id.iv_nav_back);
        feedback_content = findViewById(R.id.feedback_content);
        et_contract_info = findViewById(R.id.et_contract_info);
        Button feedback_submit=findViewById(R.id.feedback_submit);
        tv_title.setText("意见反馈");
        feedback_submit.setOnClickListener(this);
        iv_back.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_nav_back:
                finish();
                break;
            case R.id.feedback_submit:
                if (feedback_content.getText().toString().isEmpty()){
                    MToast.makeTextShort(baseContext,"请输入您要反馈给我们的信息").show();
                }else if (et_contract_info.getText().toString().isEmpty()){
                    MToast.makeTextShort(baseContext,"请输入您的联系方式,以便我们联系您").show();
                }else {
                    submint();
                }
                break;
        }
    }

    private void submint() {
        OkGo.<String>post(BaseHttp.consult_sub)
                .tag(this)
                .isMultipart(true)
                .headers("token", PreferencesUtils.getString(this,"token"))
                .params("content",feedback_content.getText().toString()+et_contract_info.getText().toString())
                .execute(new StringDialogCallback(baseContext) {
                    @Override
                    public void onSuccessResponse(Response<String> response, String msg, String msgCode) {
                        MToast.makeTextShort(FeedBackActivity.this,msg).show();
                        feedback_content.setText("");
                        et_contract_info.setText("");
                    }
                });
    }
}
